import 'package:flutter/material.dart';
import 'tabs/Category.dart';
import 'tabs/Setting.dart';
import 'tabs/Home.dart';

class Tabs extends StatefulWidget {
  final tabIndex;
  Tabs({Key? key, this.tabIndex = 0}) : super(key: key);

  @override
  _TabsState createState() => _TabsState(this.tabIndex);
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;

  _TabsState(index) {
    this._currentIndex = index;
  }

  List _pageList = [
    Homepage(),
    CategoryPage(),
    SettingPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Demo'),
      ),
      body: this._pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index) {
          print(index);
          setState(() {
            this._currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: "设置"),
        ],
      ),
      drawer: Drawer(
          child: Column(
        children: [
          Row(
            children: [
              Expanded(
                child: UserAccountsDrawerHeader(
                  accountName: Text("林夕"),
                  accountEmail: Text("49999"),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: NetworkImage(
                        "https://alifei04.cfp.cn/creative/vcg/veer/1600water/veer-303764513.jpg"),
                  ),
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: NetworkImage(
                          "https://alifei04.cfp.cn/creative/vcg/veer/1600water/veer-303764513.jpg"),
                      fit: BoxFit.cover,
                    ),
                  ),
                  otherAccountsPictures: [
                    Image.network(
                        "https://alifei04.cfp.cn/creative/vcg/veer/1600water/veer-303764513.jpg"),
                    Image.network(
                        "https://alifei04.cfp.cn/creative/vcg/veer/1600water/veer-303764513.jpg"),
                  ],
                ),
              ),
            ],
          ),
          ListTile(
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
            title: Text("我的空间"),
          ),
          Divider(),
          ListTile(
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
            title: Text("用户中心"),
            onTap: () {
              Navigator.of(context).pop();
              Navigator.pushNamed(context, '/user');
            },
          ),
          Divider(),
          ListTile(
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
            title: Text("设置中心"),
          ),
          Divider(),
          ListTile(
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
            title: Text("管理"),
          ),
          Divider(),
          ListTile(
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
            title: Text("hello"),
          ),
        ],
      )),
      endDrawer: Drawer(
        child: Text("右侧侧边栏"),
      ),
    );
  }
}
